/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpg;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import rpg.controller.HeroPosition;
import views.CharacterGraphics;

/**
 *
 * @author Emmanouil Samatas
 */
public class PlayerCharacter extends GameCharacter {

    private List<Item> inventory;
    private Weapon weapon;
    private List<Item> armor;
    private int x, y, dx, dy;
    private int experienceForNextLevel;
    private HeroPosition currentPosition = new HeroPosition();
    private HeroPosition nextPosition = new HeroPosition();
    private final int SMALL_IMAGE_SIZE = 30;

    public PlayerCharacter() {

        bigImageFileName = "BarbarianBig.png";
        ImageIcon ii = new ImageIcon(this.getClass().getResource(bigImageFileName));
        characterBigImage = ii.getImage();

        smallImageFileName = "barb.gif";
        ii = new ImageIcon(this.getClass().getResource(smallImageFileName));
        characterImage = ii.getImage();
        super.setLevel(1);

        super.setAttributes(GameCoreEngine.heroBaseAttributes);
        int vitality = super.getAttributes().get(GameCoreEngine.VITALITY);
        int strength = super.getAttributes().get(GameCoreEngine.STRENGTH);
        int intelligence = super.getAttributes().get(GameCoreEngine.INTELLIGENCE);


        //need to change!!
        super.setCharacterName("Manos");
        int maxHP = GameCoreEngine.calculateHealth(vitality);
        int maxMP = GameCoreEngine.calculateMana(intelligence);
        super.setHealthPoints(maxHP);
        super.setManaPoint(maxMP);
        super.setMaxHealthPoints(maxHP);
        super.setMaxManaPoints(maxMP);
        super.setExperience(0);
        setXpforNextLevel(500);
        
        super.setDamage(GameCoreEngine.calculateDamage(strength, weapon));
        super.setDefence(GameCoreEngine.calculateDefence(strength,armor));




    }

    public void move() {
        x += dx;
        y += dy;
        
        currentPosition.setX(x);
        currentPosition.setY(y);
        
        dx = 0;
        dy = 0;
        
    
    }
    
    public void move(int dx , int dy){
        x+= dx;
        y+= dy;
        
        nextPosition.setX(x);
        nextPosition.setY(y);
                
    }

    public int getX() {

        return currentPosition.getX();
    }

//Overide from component!!!
    public int getY() {

        return currentPosition.getY();
    }

    public void setDx(int dx) {
        this.dx = dx;
    }

    public void setDy(int dy) {
        this.dy = dy;
    }

    public void setCurrentPosition(int x , int y){
        currentPosition.setX(x);
        currentPosition.setY(y);
    }
    
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Weapon getWeapon() {
        return this.weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }
    public int getXpForNextLevel(){
        return this.experienceForNextLevel;
    }
    private void setXpforNextLevel(int exp){
        this.experienceForNextLevel = exp;
    }
    
    public void addExperience(int experience){
       currentExperience += experience;
       if(currentExperience >= experienceForNextLevel){
           levelUp();
       }
              
    }
    
    public void levelUp(){
        System.out.println("I got a level");
        int level  = super.getLevel();
        super.setLevel(level+1);
        super.setExperience(0);
        int xpForNextLevel = (110 * this.experienceForNextLevel)/100;
        this.setXpforNextLevel(xpForNextLevel);
        updateAttributes();
         super.setHealthPoints(super.getMaxHealthPoints());
         super.setManaPoint(super.getMaxManaPoints());
         System.out.println(attributes.get(GameCoreEngine.VITALITY));
       
        
        
        }
    private void updateAttributes(){
         Map<String,Integer> newAttributes = new HashMap<>();
        for(Map.Entry<String,Integer> attribute : super.getAttributes().entrySet()){
            int oldValue  = attribute.getValue();
            int newValue  = (130 * oldValue)/100;
           
           newAttributes.put(attribute.getKey(),newValue);
          
        }
         super.setAttributes(newAttributes);
            calculateCharacterProfile();
           
        }
    

    
    @Override
    public void calculateCharacterProfile() {
        int strength = getAttributes().get(GameCoreEngine.STRENGTH);
        int vitality = getAttributes().get(GameCoreEngine.VITALITY);
        int intelligence = getAttributes().get(GameCoreEngine.INTELLIGENCE);
        super.setDamage(GameCoreEngine.calculateDamage(strength, weapon));
        super.setDefence(GameCoreEngine.calculateDefence(strength,armor));
        super.setMaxHealthPoints(GameCoreEngine.calculateHealth(vitality));
        super.setMaxManaPoints(GameCoreEngine.calculateMana(intelligence));
    }
    
    

}
